﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using Water.Web.Controls.BaseInterface;
using Water.Architecture2.IDAL;

namespace Water.Web.Controls
{
    public abstract class BaseWebControl : WebControl, ICallBackable, IUpdatedableControl, IPrompt, IQueryCondition, IQuery
    {
        #region private字段

        private bool isCallBack = true;
        private string displayDuringCallBackTextControls="";

        private bool isUpdateAfterCallBack = false;
        private UpdatedableControlRenderMode renderMode = UpdatedableControlRenderMode.Div;
        private string duringCallBackText = "";
        private string updateJS="";
        private List<string> callBackControls = new List<string>();

        private int colSpan;
        private int rowSpan;
        private string prompt;

        private string queryTarget;
        private List<string> querySource = new List<string>();

        private string forMode = string.Empty;
        List<ContainerMode> modes = new List<ContainerMode>();


        #endregion

        #region override

        protected override void OnLoad(EventArgs e)
        {
            PageManager.Register(this);
            base.OnLoad(e); 
        }

        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            if (this is IUpdatedableControl)
                Marker.WriteAJAXBegin(writer, this);
            base.RenderBeginTag(writer);
        }

        public override void RenderEndTag(HtmlTextWriter writer)
        {
            base.RenderEndTag(writer);
            if (this is IUpdatedableControl)
                Marker.WriteAJAXEnd(writer, this);

        }

        #endregion

        #region ICallBackable 成员

        [Browsable(true), GlobalizeCategory("AJAX"), GlobalizeDescription("IsCallBack"), DefaultValue(true)]
        public bool IsCallBack
        {
            get
            {
                return this.isCallBack;
            }
            set
            {
                this.isCallBack = value;
            }
        }
        [Browsable(true), GlobalizeCategory("AJAX"), GlobalizeDescription("CallBackTargets")]
        public string CallBackTargets
        {
            get
            {
                if (this.IsCallBack)
                {
                    return this.displayDuringCallBackTextControls;
                }
                return string.Empty;
            }
            set
            {
                this.displayDuringCallBackTextControls = value;
            }
        }

        #endregion

        #region IUpdatableControl 成员
        [Browsable(true), GlobalizeCategory("AJAX"), GlobalizeDescription("AutoUpdatedAfterCallBack"), DefaultValue(false)]
        public virtual bool AutoUpdatedAfterCallBack
        {
            get
            {
                return this.isUpdateAfterCallBack;
            }
            set
            {
                this.isUpdateAfterCallBack = value;
            }
        }
        [Browsable(false), DefaultValue(false)]
        public virtual bool IsUpdatedAfterCallBack
        {
            get
            {
                return this.isUpdateAfterCallBack;
            }
            set
            {
                this.isUpdateAfterCallBack = value;
            }
        }

        [Browsable(true), GlobalizeCategory("AJAX"), GlobalizeDescription("DuringCallBackText")]
        public virtual string DuringCallBackText
        {
            get
            {
                if (this.duringCallBackText != null)
                {
                    return this.duringCallBackText;
                }
                return string.Empty;
            }
            set
            {
                this.duringCallBackText = value;
            }
        }
        [Browsable(true), GlobalizeCategory("AJAX"), GlobalizeDescription("RenderMode"), DefaultValue(UpdatedableControlRenderMode.Div)]
        public virtual UpdatedableControlRenderMode RenderMode
        {
            get
            {
                return this.renderMode;
            }
            set
            {
                this.renderMode = value;
            }
        }

        [Browsable(false), GlobalizeCategory("AJAX"), GlobalizeDescription("UpdateJS")]
        public virtual string  UpdateJS
        {
           get
            {
                return this.updateJS;
            }
            set
            {
                this.updateJS = value;
            }
        }

        [Browsable(false)]
        public List<string> CallBackControls
        {
            get { return callBackControls; }
            set { callBackControls = value; }
        }
        #endregion

        #region IPrompt 成员

        [Browsable(true), GlobalizeCategory("PROMPT"), GlobalizeDescription("Prompt")]
        public string Prompt
        {
            get
            {
                return this.prompt;
            }
            set
            {
                this.prompt = value;
            }
        }
        [Browsable(true), GlobalizeCategory("PROMPT"), GlobalizeDescription("ColSpan")]
        public int ColSpan
        {
            get
            {
                return this.colSpan;
            }
            set
            {
                this.colSpan = value;
            }
        }
        [Browsable(true), GlobalizeCategory("PROMPT"), GlobalizeDescription("RowSpan")]
        public int RowSpan
        {
            get
            {
                return this.rowSpan;
            }
            set
            {
                this.rowSpan = value;
            }
        }

        #endregion

        #region IQueryCondition 成员

        private string queryField;
        private string queryExpression;
        private OperatorType queryOperator;
        private string queryProperty;
        [Browsable(true), GlobalizeCategory("QUERY"), GlobalizeDescription("QueryField")]
        public string QueryField
        {
            get
            {
                return this.queryField;
            }
            set
            {
                this.queryField = value;
            }
        }
        [Browsable(true), GlobalizeCategory("QUERY"), GlobalizeDescription("QueryOperator")]
        public OperatorType QueryOperator
        {
            get
            {
                return this.queryOperator;
            }
            set
            {
                this.queryOperator = value;
            }
        }
        [Browsable(true), GlobalizeCategory("QUERY"), GlobalizeDescription("QueryExpression")]
        public string QueryExpression
        {
            get
            {
                return this.queryExpression;
            }
            set
            {
                this.queryExpression = value;
            }
        }
        [Browsable(true), GlobalizeCategory("QUERY"), GlobalizeDescription("QueryProperty")]
        public virtual string QueryProperty
        {
            get
            {
                return this.queryProperty;
            }
            set
            {
                this.queryProperty = value;
            }
        }

        #endregion

        #region IQuery 成员

        [Browsable(true), GlobalizeCategory("QUERY"), GlobalizeDescription("QueryTarget")]
        public string QueryTarget
        {
            get
            {
                return this.queryTarget;
            }
            set
            {
                this.queryTarget=value;
            }
        }

        [Browsable(false)]
        public List<string> QuerySource
        {
            get
            {
                 return this.querySource;
            }
            set
            {
                this.querySource=value;
            }
        }

        #endregion

    }
}
